import Axios from "axios";
import { apiJava } from "@/api/root";

export function getFile(url,params,fileName) {
  Axios({
    method: "post",
    url: apiJava +"/api-occupation/"+ url,
    data: params,
    responseType: "arraybuffer",
    headers: {},
    timeout: "60000",
  })
    .then((res) => {
      var blob = new Blob([res], { type: "application/vnd.ms-excel" });
      var downloadElement = document.createElement("a");
      var href = window.URL.createObjectURL(blob); //创建下载的链接
      downloadElement.href = href;
      downloadElement.download = fileName; //下载后文件名
      document.body.appendChild(downloadElement);
      downloadElement.click(); //点击下载
      document.body.removeChild(downloadElement); //下载完成移除元素
      window.URL.revokeObjectURL(href); //释放掉blob对象
    })
    .finally(() => {
      
    });
}

/**
 * 下载流文件
 */
export function downLoadFile(res, name) {
  var blob = new Blob([res], { type: "application/vnd.ms-excel" });
  var downloadElement = document.createElement("a");
  var href = window.URL.createObjectURL(blob); //创建下载的链接
  downloadElement.href = href;
  downloadElement.download = name; //下载后文件名
  document.body.appendChild(downloadElement);
  downloadElement.click(); //点击下载
  document.body.removeChild(downloadElement); //下载完成移除元素
  window.URL.revokeObjectURL(href); //释放掉blob对象
}
